package com.onedec.attendance.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
    public static final DateFormat HOUR_FORMAT= new SimpleDateFormat("HH:mm:ss");
    public static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    public static final DateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    //最早打卡时间每天六点
    public static Date getMorningStart() throws Exception {
        Date date = new Date();
        String day = DATE_FORMAT.format(date);
        String temp = day + " 06:00:00";
        return DATE_FORMAT.parse(temp);
    }

    //最早下午打卡时间12点
    public static Date getAfternoonStart() throws Exception {
        Date date = new Date();
        String day = DATE_FORMAT.format(date);
        String temp = day + " 12:00:00";
        return SDF.parse(temp);
    }

    //判断是否迟到
    public static Boolean lateMorningOrNot(Date arriveDate, Date workDate) throws Exception {
        if (arriveDate.getHours() >= getMorningStart().getHours() && arriveDate.getHours() <= workDate.getHours()) {
            if (arriveDate.getHours() == workDate.getHours() && arriveDate.getMinutes() < workDate.getMinutes()) {
                return false;
            } else return true;
        } else return true;
    }

    public static Boolean lateAfternoonOrNot(Date arriveDate, Date workDate) throws Exception {
        if (arriveDate.getHours() >= getAfternoonStart().getHours() && arriveDate.getHours() <= workDate.getHours()) {
            if (arriveDate.getHours() == workDate.getHours() && arriveDate.getMinutes() < workDate.getMinutes()) {
                return false;
            } else return true;
        } else return true;
    }

    //每天刷新打卡时间
    public static Date getFullDate(Date date) throws Exception {
        String temp = HOUR_FORMAT.format(date);
        Date date1 = SDF.parse(DATE_FORMAT.format(new Date()) + " " + temp);
        return date1;
    }
}
